<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
	<title>消息</title>
	<link rel="stylesheet" type="text/css" href="../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../css/im.css" />
</head>

<body>
	<div id="app" v-cloak>
		<div id="wrap" class="flex-wrap flex-vertical">
			<header id="header">
				<div class="im-header header-wrap">
					<div class="header-left">
						<i @click="goback" class="iconfont icon-pre"></i>
					</div>
					<div class="header-title">{{toName}}</div>
					<div @click="openUserHome" class="header-right">
						<i class="iconfont icon-user"></i>
					</div>
				</div>
			</header>
			<div id="im-main" class="im-main flex-con">
				<div id="message-list" class="message-list">
					<div v-for="(item, i) in messageList" :key="i" :class="['message-item', item.mode]">
						<div class="avatar">
							<img :src="item.avatar" alt="">
						</div>
						<div class="message-con">
							<div v-if="item.type == 'RC:TxtMsg'" class="message-text">{{item.con}}</div>
							<div v-if="item.type == 'RC:ImgTextMsg'" class="message-imgText">
								<div v-if="item.title == 'give_gift_message'" class="give-gift-message">
									<span>{{item.con}}</span>
									<img :src="item.imageUrl" alt="">
								</div>
								<div v-if="item.title == 'call_message'" class="call-message">
									<span v-if="item.mode == 'SEND'">{{item.con}}</span>
									<img :src="item.imageUrl" alt="">
									<span v-if="item.mode == 'RECEIVE'">{{item.con}}</span>
								</div>
							</div>
							<div v-if="item.type == 'RC:ImgMsg'" class="message-img">
								<img :src="item.con" alt="">
							</div>
							<div v-if="item.type == 'RC:VcMsg'" class="message-voice" :style="{ width: (item.con.duration/60)*100 + '%' }"
							 @click="playVoice(i, item)">
								<div v-if="item.mode == 'SEND'" class="voice">
									<span>{{item.con.duration}}"</span>
									<img :id="'voice' + i" src="../image/stop1.png" alt="">
								</div>
								<div v-if="item.mode == 'RECEIVE'" class="voice">
									<img :id="'voice' + i" src="../image/stop.png" alt="">
									<span>{{item.con.duration}}"</span>
								</div>
							</div>
						</div>
					</div>
				</div>

				<div v-if="voiceGif" class="voice-gif">
					<img src="../image/voice.gif" alt="">
				</div>
			</div>
			<div class="im-footer">
				<div class="input-wrap">
					<input v-model="message" type="text">
					<button @click="sendMessageText" type="button">发送</button>
				</div>
				<div class="fMenu-wrap">
					<div @click="sendMessageImage('library')" class="fMenu fMenu-img">
						<i class="iconfont icon-img"></i>
					</div>
					<div @click="sendMessageImage('camera')" class="fMenu fMenu-xiangji">
						<i class="iconfont icon-xiangji"></i>
					</div>
					<div @touchstart="voiceTouchstart" @touchend="voiceTouchend" class="fMenu fMenu-yuyin">
						<i class="iconfont icon-yuyin"></i>
					</div>
					<div @click="openGiftBox" class="fMenu fMenu-gift">
						<i class="iconfont icon-font-gift"></i>
					</div>
					<div @click="call('videoCall')" class="fMenu fMenu-call">
						<i class="iconfont icon-call"></i>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>

</html>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/vue.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script>
	var app, rong, dialogBox;
	apiready = function () {
		$api.fixStatusBar($api.dom('#header'));
		api.setStatusBarStyle({
			style: 'light',
		});
		rong = api.require('rongCloud2');
		dialogBox = api.require('dialogBox');
		app = new Vue({
			el: '#app',
			data: {
				id: $api.getStorage('uid'),
				name: $api.getStorage('uname'),
				avatar: $api.getStorage('uavatar'),
				toId: '',
				toName: '',
				toAvatar: '',
				message: '',
				messageList: [],
				voiceGif: false,
				voicePlaying: false,
				voicePlayingIndex: '',
				giftList: [],
				myinfo: {
					gold: '100',
				},
				isGiftIndex: 0,
				giftId: '',
				giftName: '',
				giftType: '',
				giftGold: '',
				red: {},
			},
			created: function () {
				var _this = this;
				api.addEventListener({
					name: 'refreshIM'
				}, function (ret, err) {
					_this.messageList.push(ret.value);
					setTimeout(function () {
						_this.msgScrollToBottom();
					}, 200);
				});
				api.addEventListener({
					name: 'keyback'
				}, function (ret, err) {
					api.sendEvent({
						name: 'refreshMessage',
					});
					api.closeWin();
				});
				api.addEventListener({
					name: 'updateIM'
				}, function (ret, err) {
					var tempExtra = JSON.parse(ret.value.result.message.content.extra);
					if (tempExtra.fromId == _this.toId) {
						var userid, username, useravatar, msgCon, title = '',
							imageUrl = '';
						if (ret.value.result.message.messageDirection == 'SEND') {
							userid = _this.id;
							username = _this.name;
							useravatar = _this.avatar;
						}
						if (ret.value.result.message.messageDirection == 'RECEIVE') {
							userid = _this.toId;
							username = _this.toName;
							useravatar = _this.toAvatar;
						}
						if (ret.value.result.message.objectName == 'RC:TxtMsg') {
							msgCon = ret.value.result.message.content.text;
						}
						if (ret.value.result.message.objectName == 'RC:ImgMsg') {
							msgCon = ret.value.result.message.content.imageUrl;
						}
						if (ret.value.result.message.objectName == 'RC:VcMsg') {
							msgCon = ret.value.result.message.content;
						}
						if (ret.value.result.message.objectName == 'RC:ImgTextMsg') {
							title = ret.value.result.message.content.title;
							msgCon = ret.value.result.message.content.description;
							imageUrl = ret.value.result.message.content.imageUrl;
						}
						_this.messageList.push({
							type: ret.value.result.message.objectName,
							title: title,
							con: msgCon,
							imageUrl: imageUrl,
							mode: ret.value.result.message.messageDirection,
							id: userid,
							name: username,
							avatar: useravatar
						})
						setTimeout(function () {
							_this.msgScrollToBottom();
						}, 500);
						rong.setMessageReceivedStatus({
							messageId: ret.value.result.message.messageId,
							receivedStatus: 'READ'
						}, function (ret, err) {})
					}
				});
				api.addEventListener({
					name: 'giveGift_showVipDialog'
				}, function (ret, err) {
					api.closeFrame({
						name: 'gift_box'
					});
					_this.showVipDialog('开通VIP即可赠送礼物');
				});
				api.addEventListener({
					name: 'giveGift_showRechargeDialog'
				}, function (ret, err) {
					api.closeFrame({
						name: 'gift_box'
					});
					_this.showRechargeDialog('您的余额不足，无法赠送礼物');
				});
				api.addEventListener({
					name: 'give_gift_notice_private'
				}, function(ret, err){
					var message_content = JSON.parse(ret.value.result.message.content.data)
					if (message_content.fromId != _this.toId) {
						return false;
					}
					if(!!message_content.GiftSvga) {
						api.openFrame({
							name: 'svga',
							url: 'svga.html',
							rect: {
								x: 0,
								y: 0,
								w: api.winWidth,
								h: api.winHeight
							},
							bounces: false,
							pageParam: message_content
						});
					}
				});
			},
			mounted: function () {
				var _this = this;
				_this.getPageParam();
				_this.getRecentMessages();
				_this.clearMessagesUnreadStatus();
				_this.getUserIndex();
				if (!!api.pageParam.from && api.pageParam.from == 'pay') {
					var message = '你好，我要充值' + api.pageParam.price + '元';
					var tempExtra = {
						fromId: _this.id,
						fromName: _this.name,
						fromAvatar: _this.avatar,
						toId: _this.toId,
						toName: _this.toName,
						toAvatar: _this.toAvatar,
					};
					rong.sendTextMessage({
						conversationType: 'PRIVATE',
						targetId: _this.toId + 'a',
						text: message,
						extra: JSON.stringify(tempExtra)
					}, function (ret, err) {
						if (err) {
							switch (err.code) {
								case 30014:
									api.toast({
										msg: '发送处理失败'
									});
									break;
								case 30003:
									api.toast({
										msg: '服务器超时'
									});
									break;
								case 31009:
									api.toast({
										msg: '用户被屏蔽'
									});
									break;
								case -10000:
									api.toast({
										msg: '未连接到服务器，请重新登录'
									});
									break;
								case -10001:
									api.toast({
										msg: '未连接到服务器，请重新登录'
									});
									break;
								case -10002:
									api.toast({
										msg: '未连接到服务器，请重新登录'
									});
									break;
								case 405:
									api.toast({
										msg: '用户在黑名单中'
									});
									break;
								default:
									break;
							}
						} else {
							_this.messageList.push({
								type: 'RC:TxtMsg',
								con: message,
								mode: 'SEND',
								id: _this.id,
								name: _this.name,
								avatar: _this.avatar
							})
							setTimeout(function () {
								_this.msgScrollToBottom();
							}, 500);
						}
					});
					api.ajax({
						url: baseUrl + 'message/push',
						method: 'post',
						headers: {
							token: $api.getStorage('deviceToken')
						},
						data: {
							values: {
								uid: $api.getStorage('uid'),
								to_uid: _this.toId,
								message: message,
							},
						}
					}, function (ret, err) {
						if (ret.status == 200) {
							
						} else {
							api.toast({
								msg: ret.message[0]
							})
						}
					})
				}
			},
			methods: {
				getUserIndex: function () {
					var _this = this;
					api.showProgress({
						title: '',
						text: ''
					});
					api.ajax({
						url: baseUrl + 'user/index',
						method: 'get',
						headers: {
							token: $api.getStorage('deviceToken')
						},
						data: {
							values: {
								uid: $api.getStorage('uid')
							},
						}
					}, function (ret, err) {
						api.hideProgress();
						if (ret.status == 200) {
							_this.myinfo = ret.data;
						}
					})
				},

				// 获取页面传参
				getPageParam: function () {
					if (api.pageParam.fromId == $api.getStorage('uid')) {
						this.toId = api.pageParam.toId;
						this.toName = api.pageParam.toName;
						this.toAvatar = api.pageParam.toAvatar;
					} else {
						this.toId = api.pageParam.fromId;
						this.toName = api.pageParam.fromName;
						this.toAvatar = api.pageParam.fromAvatar;
					}
					if (!!api.pageParam.red) {
						this.red = api.pageParam.red;
						var msg = '';
						if (this.red.type == '1') {
							msg = '正在抢一个口令红包，快去发送口令“' + this.red.password + '”吧';
						}
						if (this.red.type == '2') {
							msg = '正在抢一个照片红包，快去发送照片吧';
						}
						if (this.red.type == '3') {
							msg = '正在抢一个语音红包，快去发送语音吧';
						}
						api.alert({
							title: '提醒', 
							msg: msg
						});
					}
				},

				// 获取最近消息
				getRecentMessages: function () {
					var _this = this;
					rong.getLatestMessages({
						conversationType: 'PRIVATE',
						targetId: _this.toId + 'a',
						count: 10
					}, function (ret, err) {
						// api.alert({
						// 	title: 'getLatestMessages',
						// 	msg: JSON.stringify(ret)
						// })
						if (ret.status == 'success') {
							for (var i = 0; i < ret.result.length; i++) {
								var userid, username, useravatar, msgCon, title = '',
									imageUrl = '';
								if (ret.result[i].messageDirection == 'SEND') {
									userid = _this.id;
									username = _this.name;
									useravatar = _this.avatar;
								}
								if (ret.result[i].messageDirection == 'RECEIVE') {
									userid = _this.toId;
									username = _this.toName;
									useravatar = _this.toAvatar;
								}
								if (ret.result[i].objectName == 'RC:TxtMsg') {
									msgCon = ret.result[i].content.text;
								}
								if (ret.result[i].objectName == 'RC:ImgMsg') {
									msgCon = ret.result[i].content.imageUrl;
								}
								if (ret.result[i].objectName == 'RC:VcMsg') {
									msgCon = ret.result[i].content;
								}
								if (ret.result[i].objectName == 'RC:ImgTextMsg') {
									title = ret.result[i].content.title;
									msgCon = ret.result[i].content.description;
									imageUrl = ret.result[i].content.imageUrl;
								}
								_this.messageList.push({
									type: ret.result[i].objectName,
									title: title,
									con: msgCon,
									imageUrl: imageUrl,
									mode: ret.result[i].messageDirection,
									id: userid,
									name: username,
									avatar: useravatar
								})
							}
							_this.messageList.reverse();
							setTimeout(function () {
								_this.msgScrollToBottom();
							}, 500);
						}
					})
				},

				// 清除未读状态
				clearMessagesUnreadStatus: function () {
					rong.clearMessagesUnreadStatus({
						conversationType: 'PRIVATE',
						targetId: this.toId + 'a'
					}, function (ret, err) {})
				},

				// 滚动到底部
				msgScrollToBottom: function () {
					var ele = $api.dom('#im-main');
					ele.scrollTop = ele.scrollHeight;
				},

				// 发送文本消息
				sendMessageText: function () {
					var _this = this;
					if (_this.message == '') {
						api.toast({
							msg: '消息不能为空',
							duration: 2000,
							location: 'bottom'
						});
						return false;
					}
					if (!!_this.red.type && _this.red.type == '1') {
						if (_this.message == _this.red.password) {
							// 口令红包
							api.ajax({
								url: baseUrl + 'red/reply',
								method: 'post',
								headers: {
									token: $api.getStorage('deviceToken')
								},
								data: {
									values: {
										uid: $api.getStorage('uid'),
										id: _this.red.id,
									},
								}
							}, function (ret, err) {
								if (ret) {
									api.toast({
										msg: ret.message[0],
										duration: 2000,
										location: 'bottom'
									});
								}
							})
						} else {
							api.toast({
								msg: '您正在抢一个口令红包，口令是“' + _this.red.password + '”哟',
								duration: 3000,
								location: 'bottom'
							});
						}
					}
					api.ajax({
						url: baseUrl + 'message/push',
						method: 'post',
						headers: {
							token: $api.getStorage('deviceToken')
						},
						data: {
							values: {
								uid: $api.getStorage('uid'),
								to_uid: _this.toId,
							},
						}
					}, function (ret, err) {
						if (ret.status == 200) {
							_this.messageList.push({
								type: 'RC:TxtMsg', // RC:TxtMsg RC:VcMsg RC:ImgMsg
								con: _this.message,
								mode: 'SEND',
								id: _this.id,
								name: _this.name,
								avatar: _this.avatar
							})
							setTimeout(function () {
								_this.msgScrollToBottom();
							}, 500);
							var tempExtra = {
								fromId: _this.id,
								fromName: _this.name,
								fromAvatar: _this.avatar,
								toId: _this.toId,
								toName: _this.toName,
								toAvatar: _this.toAvatar,
							};
							rong.sendTextMessage({
								conversationType: 'PRIVATE',
								targetId: _this.toId + 'a',
								text: _this.message,
								extra: JSON.stringify(tempExtra)
							}, function (ret, err) {
								_this.message = '';
								if (err) {
									switch (err.code) {
										case 30014:
											api.toast({
												msg: '发送处理失败'
											});
											break;
										case 30003:
											api.toast({
												msg: '服务器超时'
											});
											break;
										case 31009:
											api.toast({
												msg: '用户被屏蔽'
											});
											break;
										case -10000:
											api.toast({
												msg: '未连接到服务器，请重新登录'
											});
											break;
										case -10001:
											api.toast({
												msg: '未连接到服务器，请重新登录'
											});
											break;
										case -10002:
											api.toast({
												msg: '未连接到服务器，请重新登录'
											});
											break;
										case 405:
											api.toast({
												msg: '用户在黑名单中'
											});
											break;
										default:
											break;
									}
								}
							});
						} else if (ret.status == 401) {
							_this.showRechargeDialog(ret.message[0]);
						} else {
							api.toast({
								msg: ret.message[0]
							})
						}
					})
				},

				// 发送图片消息
				sendMessageImage: function (type) {
					var _this = this;
					api.ajax({
						url: baseUrl + 'message/push',
						method: 'post',
						headers: {
							token: $api.getStorage('deviceToken')
						},
						data: {
							values: {
								uid: $api.getStorage('uid'),
								to_uid: _this.toId,
							},
						}
					}, function (ret, err) {
						if (ret.status == 200) {
							api.getPicture({
								sourceType: type,
								encodingType: 'png',
								mediaValue: 'pic',
								destinationType: 'url',
								allowEdit: false,
								saveToPhotoAlbum: false
							}, function (ret, err) {
								if (ret && ret.data != '') {
									_this.messageList.push({
										type: 'RC:ImgMsg',
										con: ret.data,
										mode: 'SEND',
										id: _this.id,
										name: _this.name,
										avatar: _this.avatar
									})
									setTimeout(function () {
										_this.msgScrollToBottom();
									}, 500);
									if (!!_this.red.type && _this.red.type == '2') {
										// 照片红包
										api.ajax({
											url: baseUrl + 'red/reply',
											method: 'post',
											headers: {
												token: $api.getStorage('deviceToken')
											},
											data: {
												values: {
													uid: $api.getStorage('uid'),
													id: _this.red.id,
												},
											}
										}, function (ret, err) {
											if (ret) {
												api.toast({
													msg: ret.message[0],
													duration: 2000,
													location: 'bottom'
												});
											}
										})
									}
									var tempExtra = {
										fromId: _this.id,
										fromName: _this.name,
										fromAvatar: _this.avatar,
										toId: _this.toId,
										toName: _this.toName,
										toAvatar: _this.toAvatar,
									};
									rong.sendImageMessage({
										conversationType: 'PRIVATE',
										targetId: _this.toId + 'a',
										imagePath: ret.data,
										extra: JSON.stringify(tempExtra)
									}, function (ret, err) {
										if (err) {
											switch (err.code) {
												case 30014:
													api.toast({
														msg: '发送处理失败'
													});
													break;
												case 30003:
													api.toast({
														msg: '服务器超时'
													});
													break;
												case 31009:
													api.toast({
														msg: '用户被屏蔽'
													});
													break;
												case -10000:
													api.toast({
														msg: '未连接到服务器，请重新登录'
													});
													break;
												case -10001:
													api.toast({
														msg: '未连接到服务器，请重新登录'
													});
													break;
												case -10002:
													api.toast({
														msg: '未连接到服务器，请重新登录'
													});
													break;
												case 405:
													api.toast({
														msg: '用户在黑名单中'
													});
													break;
												default:
													break;
											}
										}
									});
								} else if (ret.data == '') {
									api.toast({
										msg: '未选择图片'
									})
								} else {
									api.toast({
										msg: '选择图片出错，请再次尝试'
									})
								}
							});
						} else if (ret.status == 401) {
							_this.showRechargeDialog(ret.message[0]);
						} else {
							api.toast({
								msg: ret.message[0]
							})
						}
					})
				},

				voiceTouchstart: function () {
					this.voiceGif = true;
					api.startRecord({
						path: 'fs://ziyue_' + (+new Date()) + '.amr'
					});
				},

				voiceTouchend: function () {
					var _this = this;
					_this.voiceGif = false;
					api.stopRecord(function (ret, err) {
						if (ret) {
							if (ret.duration < 1) {
								api.toast({
									msg: '录音时间太短'
								})
							} else {
								_this.messageList.push({
									type: 'RC:VcMsg', // RC:TxtMsg RC:VcMsg RC:ImgMsg
									con: {
										duration: ret.duration,
										voicePath: ret.path
									},
									mode: 'SEND',
									id: _this.id,
									name: _this.name,
									avatar: _this.avatar
								})
								if (!!_this.red.type && _this.red.type == '3') {
									// 语音红包
									api.ajax({
										url: baseUrl + 'red/reply',
										method: 'post',
										headers: {
											token: $api.getStorage('deviceToken')
										},
										data: {
											values: {
												uid: $api.getStorage('uid'),
												id: _this.red.id,
											},
										}
									}, function (ret, err) {
										if (ret) {
											api.toast({
												msg: ret.message[0],
												duration: 2000,
												location: 'bottom'
											});
										}
									})
								}
								var tempExtra = {
									fromId: _this.id,
									fromName: _this.name,
									fromAvatar: _this.avatar,
									toId: _this.toId,
									toName: _this.toName,
									toAvatar: _this.toAvatar,
								};
								rong.sendVoiceMessage({
									conversationType: 'PRIVATE',
									targetId: _this.toId + 'a',
									voicePath: ret.path,
									duration: ret.duration,
									extra: JSON.stringify(tempExtra)
								}, function (ret, err) {
									if (err) {
										switch (err.code) {
											case 30014:
												api.toast({
													msg: '发送处理失败'
												});
												break;
											case 30003:
												api.toast({
													msg: '服务器超时'
												});
												break;
											case 31009:
												api.toast({
													msg: '用户被屏蔽'
												});
												break;
											case -10000:
												api.toast({
													msg: '未连接到服务器，请重新登录'
												});
												break;
											case -10001:
												api.toast({
													msg: '未连接到服务器，请重新登录'
												});
												break;
											case -10002:
												api.toast({
													msg: '未连接到服务器，请重新登录'
												});
												break;
											case 405:
												api.toast({
													msg: '用户在黑名单中'
												});
												break;
											default:
												break;
										}
									}
								});
							}
						}
					});
				},

				// 播放语音
				playVoice: function (index, item) {
					var _this = this;
					if (_this.voicePlaying) {
						api.stopPlay();
						if (item.mode == 'SEND') {
							$api.attr($api.dom('#voice' + _this.voicePlayingIndex), 'src', '../image/stop1.png');
						}
						if (item.mode == 'RECEIVE') {
							$api.attr($api.dom('#voice' + _this.voicePlayingIndex), 'src', '../image/stop.png');
						}
					} else {
						_this.voicePlaying = true;
					}
					_this.voicePlayingIndex = index;
					if (item.mode == 'SEND') {
						$api.attr($api.dom('#voice' + index), 'src', '../image/playing1.gif');
					}
					if (item.mode == 'RECEIVE') {
						$api.attr($api.dom('#voice' + index), 'src', '../image/playing.gif');
					}
					api.startPlay({
						path: item.con.voicePath
					}, function (ret, err) {
						if (item.mode == 'SEND') {
							$api.attr($api.dom('#voice' + index), 'src', '../image/stop1.png');
						}
						if (item.mode == 'RECEIVE') {
							$api.attr($api.dom('#voice' + index), 'src', '../image/stop.png');
						}
					});
				},

				showVipDialog: function (title) {
					dialogBox.raffle({
						texts: {
							mainText: title,
							subText: '',
							leftTitle: '开通会员'
						},
						styles: {
							bg: '#272320',
							w: 300,
							corner: 2,
							icon: {
								marginT: 20,
								w: 40,
								h: 40,
								corner: 20,
								iconPath: 'widget://image/icon_big_vip.png'
							},
							main: {
								marginT: 10,
								color: '#fff',
								size: 14,
							},
							sub: {
								marginT: 10
							},
							left: {
								w: 300,
								h: 50,
								marginL: 0,
								marginB: 0,
								corner: 2,
								bg: '#000',
								color: '#fff',
								size: 16
							}
						},
						tapClose: true
					}, function (ret, err) {
						if (ret.eventType == 'left') {
							dialogBox.close({
								dialogName: 'raffle'
							});
							api.openWin({
								name: 'my_vip',
								url: 'my_vip.html',
								slidBackEnabled: false
							});
						}
					});
				},

				openGiftBox: function () {
					var _this = this;
					api.openFrame({
						name: 'gift',
						url: 'gift.html',
						rect: {
							x: 0,
							y: 0,
							w: api.winWidth,
							h: api.winHeight
						},
						pageParam: {
							to_uid: _this.toId,
							to_uname: _this.toName,
							to_uavatar: _this.toAvatar
						}
					});
				},

				showActionSheet: function () {
					var _this = this;
					if (_this.toId == '2') {
						api.toast({
							msg: '不能给客服人员视频'
						})
						return false;
					}
					api.actionSheet({
						title: '',
						cancelTitle: '取消',
						destructiveTitle: '',
						buttons: ['语音通话', '视频通话']
					}, function (ret, err) {
						if (ret) {
							if (ret.buttonIndex == 1) {
								_this.call('voiceCall');
							}
							if (ret.buttonIndex == 2) {
								_this.call('videoCall');
							}
						}
					});
				},

				call: function (type) {
					var _this = this;
					var tempExtra = {
						fromId: _this.id,
						fromName: _this.name,
						fromAvatar: _this.avatar,
						toId: _this.toId,
						toName: _this.toName,
						toAvatar: _this.toAvatar,
					};
					// 发起视频
					api.ajax({
						url: baseUrl + 'message/videoCall',
						method: 'post',
						headers: {
							token: $api.getStorage('deviceToken')
						},
						data: {
							values: {
								uid: $api.getStorage('uid'),
								from_uid: $api.getStorage('uid'),
								to_uid: _this.toId,
								type: '0',
							},
						}
					}, function (ret, err) {
						if (ret.status == 200) {
							api.openWin({
								name: 'call',
								url: 'call1.html',
								slidBackEnabled: false,
								pageParam: {
									extra: tempExtra,
									type: type,
									time: ret.data.time,
								}
							});
						} else if (ret.status == 401) {
							_this.showRechargeDialog(ret.message[0]);
						} else {
							api.toast({
								msg: ret.message[0]
							})
						}
					})
				},

				showRechargeDialog: function (title) {
					dialogBox.evaluation({
						styles: {
							bg: '#fff',
							corner: 2,
							w: 300,
							title: {
								marginT: 20,
								size: 14,
								h: 50,
								color: '#000',
								bold: true,
								borderColor: '#eee',
								borderWidth: 1
							},
							buttons: [{
								w: 300,
								h: 50,
								color: '#0077ff',
								size: 14,
								borderColor: '#eee',
								borderWidth: 1
							}, {
								w: 300,
								h: 50,
								color: '#0077ff',
								size: 14,
								borderColor: '#eee',
								borderWidth: 1
							}, {
								w: 300,
								h: 50,
								color: '#000',
								size: 14
							}]
						},
						texts: {
							title: title,
							buttons: [{
								text: '去赚钱'
							}, {
								text: '去充值'
							}, {
								text: '取消'
							}]
						},
						tapClose: true
					}, function (ret, err) {
						if (ret) {
							if (ret.index == 0) {
								dialogBox.close({
									dialogName: 'evaluation'
								});
								api.openWin({
									name: 'my_share',
									url: 'my_share.html',
									slidBackEnabled: false
								});
							}
							if (ret.index == 1) {
								dialogBox.close({
									dialogName: 'evaluation'
								});
								api.openWin({
									name: 'recharge',
									url: 'recharge.html',
									slidBackEnabled: false
								});
							}
							if (ret.index == 2) {
								dialogBox.close({
									dialogName: 'evaluation'
								});
							}
						}
					});
				},

				goback: function () {
					api.sendEvent({
						name: 'refreshMessage',
					});
					api.closeWin();
				},

				openUserHome: function () {
					var _this = this;
					api.openWin({
						name: 'user_home',
						url: 'user_home.html',
						slidBackEnabled: false,
						pageParam: {
							member_id: _this.toId
						}
					});
				},

			},
		})
	}
</script>